home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_emacs.idb / usr / freeware / info / emacs-12.z / emacs-12
Encoding:
GNU Info File  |  1998-10-28  |  48.5 KB  |  1,226 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.63 from the
  2. input file emacs.texi.
  3.  
  4. 
  5. File: emacs,  Node: Multi-line Indent,  Next: Lisp Indent,  Prev: Basic Indent,  Up: Program Indent
  6.  
  7. Indenting Several Lines
  8. -----------------------
  9.  
  10.    When you wish to re-indent several lines of code which have been
  11. altered or moved to a different level in the list structure, you have
  12. several commands available.
  13.  
  14. `C-M-q'
  15.      Re-indent all the lines within one list (`indent-sexp').
  16.  
  17. `C-u TAB'
  18.      Shift an entire list rigidly sideways so that its first line is
  19.      properly indented.
  20.  
  21. `C-M-\'
  22.      Re-indent all lines in the region (`indent-region').
  23.  
  24.    You can re-indent the contents of a single list by positioning point
  25. before the beginning of it and typing `C-M-q' (`indent-sexp' in Lisp
  26. mode, `indent-c-exp' in C mode; also bound to other suitable commands
  27. in other modes).  The indentation of the line the sexp starts on is not
  28. changed; therefore, only the relative indentation within the list, and
  29. not its position, is changed.  To correct the position as well, type a
  30. TAB before the `C-M-q'.
  31.  
  32.    If the relative indentation within a list is correct but the
  33. indentation of its first line is not, go to that line and type `C-u
  34. TAB'.  TAB with a numeric argument reindents the current line as usual,
  35. then reindents by the same amount all the lines in the grouping
  36. starting on the current line.  In other words, it reindents the whole
  37. grouping rigidly as a unit.  It is clever, though, and does not alter
  38. lines that start inside strings, or C preprocessor lines when in C mode.
  39.  
  40.    Another way to specify the range to be re-indented is with the
  41. region.  The command `C-M-\' (`indent-region') applies TAB to every
  42. line whose first character is between point and mark.
  43.  
  44. 
  45. File: emacs,  Node: Lisp Indent,  Next: C Indent,  Prev: Multi-line Indent,  Up: Program Indent
  46.  
  47. Customizing Lisp Indentation
  48. ----------------------------
  49.  
  50.    The indentation pattern for a Lisp expression can depend on the
  51. function called by the expression.  For each Lisp function, you can
  52. choose among several predefined patterns of indentation, or define an
  53. arbitrary one with a Lisp program.
  54.  
  55.    The standard pattern of indentation is as follows: the second line
  56. of the expression is indented under the first argument, if that is on
  57. the same line as the beginning of the expression; otherwise, the second
  58. line is indented underneath the function name.  Each following line is
  59. indented under the previous line whose nesting depth is the same.
  60.  
  61.    If the variable `lisp-indent-offset' is non-`nil', it overrides the
  62. usual indentation pattern for the second line of an expression, so that
  63. such lines are always indented `lisp-indent-offset' more columns than
  64. the containing list.
  65.  
  66.    The standard pattern is overridden for certain functions.  Functions
  67. whose names start with `def' always indent the second line by
  68. `lisp-body-indent' extra columns beyond the open-parenthesis starting
  69. the expression.
  70.  
  71.    The standard pattern can be overridden in various ways for individual
  72. functions, according to the `lisp-indent-function' property of the
  73. function name.  There are four possibilities for this property:
  74.  
  75. `nil'
  76.      This is the same as no property; the standard indentation pattern
  77.      is used.
  78.  
  79. `defun'
  80.      The pattern used for function names that start with `def' is used
  81.      for this function also.
  82.  
  83. a number, NUMBER
  84.      The first NUMBER arguments of the function are "distinguished"
  85.      arguments; the rest are considered the "body" of the expression.
  86.      A line in the expression is indented according to whether the
  87.      first argument on it is distinguished or not.  If the argument is
  88.      part of the body, the line is indented `lisp-body-indent' more
  89.      columns than the open-parenthesis starting the containing
  90.      expression.  If the argument is distinguished and is either the
  91.      first or second argument, it is indented *twice* that many extra
  92.      columns.  If the argument is distinguished and not the first or
  93.      second argument, the standard pattern is followed for that line.
  94.  
  95. a symbol, SYMBOL
  96.      SYMBOL should be a function name; that function is called to
  97.      calculate the indentation of a line within this expression.  The
  98.      function receives two arguments:
  99.     STATE
  100.           The value returned by `parse-partial-sexp' (a Lisp primitive
  101.           for indentation and nesting computation) when it parses up to
  102.           the beginning of this line.
  103.  
  104.     POS
  105.           The position at which the line being indented begins.
  106.  
  107.      It should return either a number, which is the number of columns of
  108.      indentation for that line, or a list whose car is such a number.
  109.      The difference between returning a number and returning a list is
  110.      that a number says that all following lines at the same nesting
  111.      level should be indented just like this one; a list says that
  112.      following lines might call for different indentations.  This makes
  113.      a difference when the indentation is being computed by `C-M-q'; if
  114.      the value is a number, `C-M-q' need not recalculate indentation
  115.      for the following lines until the end of the list.
  116.  
  117. 
  118. File: emacs,  Node: C Indent,  Next: Custom C Indent,  Prev: Lisp Indent,  Up: Program Indent
  119.  
  120. Commands for C Indentation
  121. --------------------------
  122.  
  123.    Here are the commands for indentation in C mode and related modes:
  124.  
  125. `C-c C-q'
  126.      Reindent the current top-level function definition or aggregate
  127.      type declaration (`c-indent-defun').
  128.  
  129. `C-M-q'
  130.      Reindent each line in the balanced expression that follows point
  131.      (`c-indent-exp').  A prefix argument inhibits error checking and
  132.      warning messages about invalid syntax.
  133.  
  134. `TAB'
  135.      Reindent the current line, and/or in some cases insert a tab
  136.      character (`c-indent-command').
  137.  
  138.      If `c-tab-always-indent' is `t', this command always reindents the
  139.      current line and does nothing else.  This is the default.
  140.  
  141.      If that variable is `nil', this command reindents the current line
  142.      only if point is at the left margin or in the line's indentation;
  143.      otherwise, it inserts a tab.
  144.  
  145.      Any other value (not `nil' or `t') means always reindent the line,
  146.      and also insert a tab if within a comment, a string, or a
  147.      preprocessor directive.
  148.  
  149. `C-u TAB'
  150.      Reindent the current line according to its syntax; also rigidly
  151.      reindent any other lines of the expression that starts on the
  152.      current line.  *Note Multi-line Indent::.
  153.  
  154.    To reindent the whole current buffer, type `C-x h C-M-\'.  This
  155. first selects the whole buffer as the region, then reindents that
  156. region.
  157.  
  158.    To reindent the current block, use `C-M-u C-M-q'.  This moves to the
  159. front of the block and then reindents it all.
  160.  
  161. 
  162. File: emacs,  Node: Custom C Indent,  Prev: C Indent,  Up: Program Indent
  163.  
  164. Customizing C Indentation
  165. -------------------------
  166.  
  167.    C mode and related modes use a simple yet flexible mechanism for
  168. customizing indentation.  The mechanism works in two steps: first it
  169. classifies the line syntactically according to its contents and context;
  170. second, it associates each kind of syntactic construct with an
  171. indentation offset which you can customize.
  172.  
  173. * Menu:
  174.  
  175. * Syntactic Analysis::
  176. * Indentation Calculation::
  177. * Changing Indent Style::
  178. * Syntactic Symbols::
  179. * Variables for C Indent::
  180. * C Indent Styles::
  181.  
  182. 
  183. File: emacs,  Node: Syntactic Analysis,  Next: Indentation Calculation,  Up: Custom C Indent
  184.  
  185. Step 1--Syntactic Analysis
  186. ..........................
  187.  
  188.    In the first step, the C indentation mechanism looks at the line you
  189. are currently indenting and determines the syntactic components of the
  190. construct on that line.  It builds a list of these syntactic components,
  191. where each component on the list contains a "syntactic symbol" and a
  192. relative buffer position.  Syntactic symbols describe grammatical
  193. elements such as STATEMENT, SUBSTATEMENT, CLASS-OPEN, CLASS-CLOSE,
  194. KNR-ARGDECL, etc.
  195.  
  196.    Conceptually, a line of C code is always indented relative to the
  197. indentation of some line higher up in the buffer.  This is represented
  198. by the relative buffer positions in the syntactic component list.
  199.  
  200.    Here is an example.  Suppose we have the following code in a C++ mode
  201. buffer (the line numbers don't actually appear in the buffer):
  202.  
  203.      1: void swap (int& a, int& b)
  204.      2: {
  205.      3:   int tmp = a;
  206.      4:   a = b;
  207.      5:   b = tmp;
  208.      6: }
  209.  
  210.    If you type `C-c C-s' (which runs the command
  211. `c-show-syntactic-information') on line 4, it shows the result of the
  212. indentation mechanism for that line:
  213.  
  214.      ((statement . 32))
  215.  
  216.    This indicates that the line is a statement and it is indented
  217. relative to buffer position 32, which happens to be the `i' in `int' on
  218. line 3.  If you move the cursor to line 3 and type `C-c C-s', it
  219. displays this:
  220.  
  221.      ((defun-block-intro . 28))
  222.  
  223.    This indicates that the `int' line is the first statement in a
  224. block, and is indented relative to buffer position 28, which is the
  225. brace just after the function header.
  226.  
  227. Here is another example:
  228.  
  229.      1: int add (int val, int incr, int doit)
  230.      2: {
  231.      3:   if (doit)
  232.      4:     {
  233.      5:       return (val + incr);
  234.      6:     }
  235.      7:   return (val);
  236.      8: }
  237.  
  238. Typing `C-c C-s' on line 4 displays this:
  239.  
  240.      ((substatement-open . 43))
  241.  
  242.    This says that the brace *opens* a substatement block.  By the way,
  243. a "substatement" indicates the line after an `if', `else', `while',
  244. `do', `switch', and `for' statements.
  245.  
  246.    After a line has been analyzed syntactically for indentation, the
  247. global variable `c-syntactic-context' contains a list that describes
  248. the results.  Each element in this list is a a "syntactic component": a
  249. cons cell containing a syntactic symbol and (optionally) its
  250. corresponding buffer position.  There may be several elements in a
  251. component list; typically only one element has a buffer position.
  252.  
  253. 
  254. File: emacs,  Node: Indentation Calculation,  Next: Changing Indent Style,  Prev: Syntactic Analysis,  Up: Custom C Indent
  255.  
  256. Step 2--Indentation Calculation
  257. ...............................
  258.  
  259.    The C indentation mechanism calculates the indentation for the
  260. current line using the list of syntactic components,
  261. `c-syntactic-context', derived from syntactic analysis.  Each component
  262. is a cons cell that contains a syntactic symbol and may also contain a
  263. pointer to a location in the buffer.
  264.  
  265.    Each component contributes to the final total indentation of the line
  266. in two ways.  First, the syntactic symbol identifies an element of
  267. `c-offsets-alist', which is an association list mapping syntactic
  268. symbols into indentation offsets.  Each syntactic symbol's offset adds
  269. to the total indentation.  Second, if the component includes a buffer
  270. position, the column number of that position adds to the indentation.
  271. All these offsets and column numbers, added together, give the total
  272. indentation.
  273.  
  274.    The following examples demonstrate the workings of the C indentation
  275. mechanism:
  276.  
  277.      1: void swap (int& a, int& b)
  278.      2: {
  279.      3:   int tmp = a;
  280.      4:   a = b;
  281.      5:   b = tmp;
  282.      6: }
  283.  
  284.    Suppose that point is on line 3 and you type TAB to reindent the
  285. line.  As explained above (*note Syntactic Analysis::.), the syntactic
  286. component list for that line is:
  287.  
  288.      ((defun-block-intro . 28))
  289.  
  290.    In this case, the indentation calculation first looks up
  291. `defun-block-intro' in the `c-offsets-alist' alist.  Suppose that it
  292. finds the integer 2; it adds this to the running total (initialized to
  293. zero), yielding a updated total indentation of 2 spaces.
  294.  
  295.    The next step is to find the column number of buffer position 28.
  296. Since the brace at buffer position 28 is in column zero, this adds 0 to
  297. the running total.  Since this line has only one syntactic component,
  298. the total indentation for the line is 2 spaces.
  299.  
  300.      1: int add (int val, int incr, int doit)
  301.      2: {
  302.      3:   if (doit)
  303.      4:     {
  304.      5:       return(val + incr);
  305.      6:     }
  306.      7:   return(val);
  307.      8: }
  308.  
  309.    If you type TAB on line 4, the same process is performed, but with
  310. different data.  The syntactic component list for this line is:
  311.  
  312.      ((substatement-open . 43))
  313.  
  314.    Here, the indentation calculation's first job is to look up the
  315. symbol `substatement-open' in `c-offsets-alist'.  Let's assume that the
  316. offset for this symbol is 2.  At this point the running total is 2 (0 +
  317. 2 = 2).  Then it adds the column number of buffer position 43, which is
  318. the `i' in `if' on line 3.  This character is in column 2 on that line.
  319. Adding this yields a total indentation of 4 spaces.
  320.  
  321.    If a syntactic symbol in the analysis of a line does not appear in
  322. `c-offsets-alist', it is ignored; if in addition the variable
  323. `c-strict-syntax-p' is non-`nil', it is an error.
  324.  
  325. 
  326. File: emacs,  Node: Changing Indent Style,  Next: Syntactic Symbols,  Prev: Indentation Calculation,  Up: Custom C Indent
  327.  
  328. Changing Indentation Style
  329. ..........................
  330.  
  331.    There are two ways to customize the indentation style for the C
  332. modes.  First, you can select one of several predefined styles, each of
  333. which specifies offsets for all the syntactic symbols.  For more
  334. flexibility, you can customize the handling of individual syntactic
  335. symbols.  *Note Syntactic Symbols::, for a list of all defined
  336. syntactic symbols.
  337.  
  338. `M-x c-set-style RET STYLE RET'
  339.      Select predefined indentation style STYLE.  Type `?' when entering
  340.      STYLE to see a list of supported styles; to find out what a style
  341.      looks like, select it and reindent some C code.
  342.  
  343. `C-c C-o SYMBOL RET OFFSET RET'
  344.      Set the indentation offset for syntactic symbol SYMBOL
  345.      (`c-set-offset').  The second argument OFFSET specifies the new
  346.      indentation offset.
  347.  
  348.    The `c-offsets-alist' variable controls the amount of indentation to
  349. give to each syntactic symbol.  Its value is an association list, and
  350. each element of the list has the form `(SYNTACTIC-SYMBOL . OFFSET)'.
  351. By changing the offsets for various syntactic symbols, you can
  352. customize indentation in fine detail.
  353.  
  354.    Each offset value in `c-offsets-alist' can be an integer, a function
  355. or variable name, or one of the following symbols: `+', `-', `++', or
  356. `--', indicating positive or negative multiples of the variable
  357. `c-basic-offset'.  Thus, if you want to change the levels of
  358. indentation to be 3 spaces instead of 2 spaces, set `c-basic-offset' to
  359. 3.
  360.  
  361.    Using a function as the offset value provides the ultimate
  362. flexibility in customizing indentation.  The function is called with a
  363. single argument containing the `cons' of the syntactic symbol and the
  364. relative indent point.  The function should return an integer offset.
  365.  
  366.    The command `C-c C-o' (`c-set-offset') is the easiest way to set
  367. offsets, both interactively or in your `~/.emacs' file.  First specify
  368. the syntactic symbol, then the offset you want.  *Note Syntactic
  369. Symbols::, for a list of valid syntactic symbols and their meanings.
  370.  
  371.    The variable `c-offsets-alist-default' holds the default settings
  372. for the offsets of the syntactic symbols.  *Do not change this value!*
  373.  
  374. 
  375. File: emacs,  Node: Syntactic Symbols,  Next: Variables for C Indent,  Prev: Changing Indent Style,  Up: Custom C Indent
  376.  
  377. Syntactic Symbols
  378. .................
  379.  
  380.    Here is a table of valid syntactic symbols for C mode indentation,
  381. with their syntactic meanings.  Normally, most of these symbols are
  382. assigned offsets in `c-offsets-alist'.
  383.  
  384. `string'
  385.      Inside a multi-line string.
  386.  
  387. `c'
  388.      Inside a multi-line C style block comment.
  389.  
  390. `defun-open'
  391.      On a brace that opens a function definition.
  392.  
  393. `defun-close'
  394.      On a brace that closes a function definition.
  395.  
  396. `defun-block-intro'
  397.      In the first line in a top-level defun.
  398.  
  399. `class-open'
  400.      On a brace that opens a class definition.
  401.  
  402. `class-close'
  403.      On a brace that closes a class definition.
  404.  
  405. `inline-open'
  406.      On a brace that opens an in-class inline method.
  407.  
  408. `inline-close'
  409.      On a brace that closes an in-class inline method.
  410.  
  411. `ansi-funcdecl-cont'
  412.      In the nether region between an ANSI function declaration and the
  413.      defun opening brace.
  414.  
  415. `knr-argdecl-intro'
  416.      On the first line of a K&R C argument declaration.
  417.  
  418. `knr-argdecl'
  419.      In one of the subsequent lines in a K&R C argument declaration.
  420.  
  421. `topmost-intro'
  422.      On the first line in a topmost construct definition.
  423.  
  424. `topmost-intro-cont'
  425.      On the topmost definition continuation lines.
  426.  
  427. `member-init-intro'
  428.      On the first line in a member initialization list.
  429.  
  430. `member-init-cont'
  431.      On one of the subsequent member initialization list lines.
  432.  
  433. `inher-intro'
  434.      On the first line of a multiple inheritance list.
  435.  
  436. `inher-cont'
  437.      On one of the subsequent multiple inheritance lines.
  438.  
  439. `block-open'
  440.      On a statement block open brace.
  441.  
  442. `block-close'
  443.      On a statement block close brace.
  444.  
  445. `brace-list-open'
  446.      On the opening brace of an `enum' or `static' array list.
  447.  
  448. `brace-list-close'
  449.      On the closing brace of an `enum' or `static' array list.
  450.  
  451. `brace-list-intro'
  452.      On the first line in an `enum' or `static' array list.
  453.  
  454. `brace-list-entry'
  455.      On one of the subsequent lines in an `enum' or `static' array list.
  456.  
  457. `statement'
  458.      On an ordinary statement.
  459.  
  460. `statement-cont'
  461.      On a continuation line of a statement.
  462.  
  463. `statement-block-intro'
  464.      On the first line in a new statement block.
  465.  
  466. `statement-case-intro'
  467.      On the first line in a `case' "block".
  468.  
  469. `statement-case-open'
  470.      On the first line in a `case' block starting with brace.
  471.  
  472. `substatement'
  473.      On the first line after an `if', `while', `for', `do', or `else'.
  474.  
  475. `substatement-open'
  476.      On the brace that opens a substatement block.
  477.  
  478. `case-label'
  479.      On a `case' or `default' label.
  480.  
  481. `access-label'
  482.      On a C++ `private', `protected', or `public' access label.
  483.  
  484. `label'
  485.      On any ordinary label.
  486.  
  487. `do-while-closure'
  488.      On the `while' that ends a `do'-`while' construct.
  489.  
  490. `else-clause'
  491.      On the `else' of an `if'-`else' construct.
  492.  
  493. `comment-intro'
  494.      On a line containing only a comment introduction.
  495.  
  496. `arglist-intro'
  497.      On the first line in an argument list.
  498.  
  499. `arglist-cont'
  500.      On one of the subsequent argument list lines when no arguments
  501.      follow on the same line as the the arglist opening parenthesis.
  502.  
  503. `arglist-cont-nonempty'
  504.      On one of the subsequent argument list lines when at least one
  505.      argument follows on the same line as the arglist opening
  506.      parenthesis.
  507.  
  508. `arglist-close'
  509.      On the closing parenthesis of an argument list.
  510.  
  511. `stream-op'
  512.      On one of the lines continuing a stream operator construct.
  513.  
  514. `inclass'
  515.      On a construct which is nested inside a class definition.
  516.  
  517. `cpp-macro'
  518.      On the start of a cpp macro.
  519.  
  520. `friend'
  521.      On a C++ `friend' declaration.
  522.  
  523. `objc-method-intro'
  524.      On the first line of an Objective-C method definition.
  525.  
  526. `objc-method-args-cont'
  527.      On one of the lines continuing an Objective-C method definition.
  528.  
  529. `objc-method-call-cont'
  530.      On one of the lines continuing an Objective-C method call.
  531.  
  532. 
  533. File: emacs,  Node: Variables for C Indent,  Next: C Indent Styles,  Prev: Syntactic Symbols,  Up: Custom C Indent
  534.  
  535. Variables for C Indentation
  536. ...........................
  537.  
  538.    This section describes additional variables which control the
  539. indentation behavior of C mode and related mode.
  540.  
  541. `c-offsets-alist'
  542.      Association list of syntactic symbols and their indentation
  543.      offsets.  *Note Changing Indent Style::, for details.
  544.  
  545. `c-offsets-alist-default'
  546.      Default settings for the offsets of the syntactic symbols.  *Note
  547.      Changing Indent Style::.
  548.  
  549. `c-style-alist'
  550.      Variable for specifying styles of indentation; see below.
  551.  
  552. `c-basic-offset'
  553.      Amount of basic offset used by `+' and `-' symbols in
  554.      `c-offsets-alist'.
  555.  
  556. `c-recognize-knr-p'
  557.      If this variable is non-`nil', C mode and Objective C mode
  558.      recognize K&R constructs.  This variable is needed because of
  559.      ambiguities in C syntax that make recognition of K&R constructs
  560.      problematic and slow.  If you always use ANSI C prototype syntax,
  561.      set this variable to `nil' to speed up C indentation.
  562.  
  563.      This variable is `nil' by default in C++ mode, and `t' by default
  564.      in C mode and Objective C mode.
  565.  
  566. `c-special-indent-hook'
  567.      Hook for user-defined special indentation adjustments.  This hook
  568.      is called after a line is indented by C mode and related modes.
  569.  
  570.    The variable `c-style-alist' specifies the predefined indentation
  571. styles.  Each element has form `(NAME VARIABLE-SETTING...)', where NAME
  572. is the name of the style.  Each VARIABLE-SETTING has the form `(VARIABLE
  573. . VALUE)'; VARIABLE is one of the customization variables used by C
  574. mode, and VALUE is the value for that variable when using the selected
  575. style.
  576.  
  577.    When VARIABLE is `c-offsets-alist', that is a special case: VALUE is
  578. appended to the front of the value of `c-offsets-alist' instead of
  579. replacing that value outright.  Therefore, it is not necessary for
  580. VALUE to specify each and every syntactic symbol--only those for which
  581. the style differs from the default.
  582.  
  583.    The indentation of lines containing only comments is also affected by
  584. the variable `c-comment-only-line-offset' (*note Comments in C::.).
  585.  
  586. 
  587. File: emacs,  Node: C Indent Styles,  Prev: Variables for C Indent,  Up: Custom C Indent
  588.  
  589. C Indentation Styles
  590. ....................
  591.  
  592.    A "C style" is a collection of indentation style customizations.
  593. Emacs comes with several predefined indentation styles for C code
  594. including `gnu', `k&r', `bsd', `stroustrup' `whitesmith', `ellemtel',
  595. and `cc-mode'.  The default style is `gnu'.
  596.  
  597.    To choose the style you want, use the command `M-x c-set-style'.
  598. Specify a style name as an argument (case is not significant in C style
  599. names).  The chosen style only affects newly visited buffers, not those
  600. you are already editing.
  601.  
  602.    To define a new C indentation style, call the function `c-add-style':
  603.  
  604.      (c-add-style NAME VALUES USE-NOW)
  605.  
  606. Here NAME is the name of the new style (a string), and VALUES is an
  607. alist whose elements have the form `(VARIABLE . VALUE)'.  The variables
  608. you specify should be among those documented in *Note Variables for C
  609. Indent::.
  610.  
  611.    If USE-NOW is non-`nil', `c-add-style' switches to the new style
  612. after defining it.
  613.  
  614. 
  615. File: emacs,  Node: Matching,  Next: Comments,  Prev: Program Indent,  Up: Programs
  616.  
  617. Automatic Display Of Matching Parentheses
  618. =========================================
  619.  
  620.    The Emacs parenthesis-matching feature is designed to show
  621. automatically how parentheses match in the text.  Whenever you type a
  622. self-inserting character that is a closing delimiter, the cursor moves
  623. momentarily to the location of the matching opening delimiter, provided
  624. that is on the screen.  If it is not on the screen, some text near it is
  625. displayed in the echo area.  Either way, you can tell what grouping is
  626. being closed off.
  627.  
  628.    In Lisp, automatic matching applies only to parentheses.  In C, it
  629. applies to braces and brackets too.  Emacs knows which characters to
  630. regard as matching delimiters based on the syntax table, which is set
  631. by the major mode.  *Note Syntax::.
  632.  
  633.    If the opening delimiter and closing delimiter are mismatched--such
  634. as in `[x)'--a warning message is displayed in the echo area.  The
  635. correct matches are specified in the syntax table.
  636.  
  637.    Three variables control parenthesis match display.
  638. `blink-matching-paren' turns the feature on or off; `nil' turns it off,
  639. but the default is `t' to turn match display on.
  640. `blink-matching-delay' says how many seconds to wait; the default is 1,
  641. but on some systems it is useful to specify a fraction of a second.
  642. `blink-matching-paren-distance' specifies how many characters back to
  643. search to find the matching opening delimiter.  If the match is not
  644. found in that far, scanning stops, and nothing is displayed.  This is
  645. to prevent scanning for the matching delimiter from wasting lots of
  646. time when there is no match.  The default is 12,000.
  647.  
  648.    When using X Windows, you can request a more powerful kind of
  649. automatic parenthesis matching by loading the `paren' library.  To load
  650. it, type `M-x load-library RET paren RET'.  This library turns off the
  651. usual kind of matching parenthesis display and substitutes another:
  652. whenever point is after a close parenthesis, the close parenthesis and
  653. its matching open parenthesis are both highlighted; otherwise, if point
  654. is before an open parenthesis, the matching close parenthesis is
  655. highlighted.  (There is no need to highlight the open parenthesis after
  656. point because the cursor appears on top of that character.)
  657.  
  658. 
  659. File: emacs,  Node: Comments,  Next: Balanced Editing,  Prev: Matching,  Up: Programs
  660.  
  661. Manipulating Comments
  662. =====================
  663.  
  664.    Because comments are such an important part of programming, Emacs
  665. provides special commands for editing and inserting comments.
  666.  
  667. * Menu:
  668.  
  669. * Comment Commands::
  670. * Multi-Line Comments::
  671. * Options for Comments::
  672.  
  673. 
  674. File: emacs,  Node: Comment Commands,  Next: Multi-Line Comments,  Up: Comments
  675.  
  676. Comment Commands
  677. ----------------
  678.  
  679.    The comment commands insert, kill and align comments.
  680.  
  681. `M-;'
  682.      Insert or align comment (`indent-for-comment').
  683.  
  684. `C-x ;'
  685.      Set comment column (`set-comment-column').
  686.  
  687. `C-u - C-x ;'
  688.      Kill comment on current line (`kill-comment').
  689.  
  690. `M-LFD'
  691.      Like RET followed by inserting and aligning a comment
  692.      (`indent-new-comment-line').
  693.  
  694. `M-x comment-region'
  695.      Add or remove comment delimiters on all the lines in the region.
  696.  
  697.    The command that creates a comment is `M-;' (`indent-for-comment').
  698. If there is no comment already on the line, a new comment is created,
  699. aligned at a specific column called the "comment column".  The comment
  700. is created by inserting the string Emacs thinks comments should start
  701. with (the value of `comment-start'; see below).  Point is left after
  702. that string.  If the text of the line extends past the comment column,
  703. then the indentation is done to a suitable boundary (usually, at least
  704. one space is inserted).  If the major mode has specified a string to
  705. terminate comments, that is inserted after point, to keep the syntax
  706. valid.
  707.  
  708.    `M-;' can also be used to align an existing comment.  If a line
  709. already contains the string that starts comments, then `M-;' just moves
  710. point after it and re-indents it to the conventional place.  Exception:
  711. comments starting in column 0 are not moved.
  712.  
  713.    Some major modes have special rules for indenting certain kinds of
  714. comments in certain contexts.  For example, in Lisp code, comments which
  715. start with two semicolons are indented as if they were lines of code,
  716. instead of at the comment column.  Comments which start with three
  717. semicolons are supposed to start at the left margin.  Emacs understands
  718. these conventions by indenting a double-semicolon comment using TAB,
  719. and by not changing the indentation of a triple-semicolon comment at
  720. all.
  721.  
  722.      ;; This function is just an example
  723.      ;;; Here either two or three semicolons are appropriate.
  724.      (defun foo (x)
  725.      ;;; And now, the first part of the function:
  726.        ;; The following line adds one.
  727.        (1+ x))           ; This line adds one.
  728.  
  729.    In C code, a comment preceded on its line by nothing but whitespace
  730. is indented like a line of code.
  731.  
  732.    Even when an existing comment is properly aligned, `M-;' is still
  733. useful for moving directly to the start of the comment.
  734.  
  735.    `C-u - C-x ;' (`kill-comment') kills the comment on the current line,
  736. if there is one.  The indentation before the start of the comment is
  737. killed as well.  If there does not appear to be a comment in the line,
  738. nothing is done.  To reinsert the comment on another line, move to the
  739. end of that line, do `C-y', and then do `M-;' to realign it.  Note that
  740. `C-u - C-x ;' is not a distinct key; it is `C-x ;'
  741. (`set-comment-column') with a negative argument.  That command is
  742. programmed so that when it receives a negative argument it calls
  743. `kill-comment'.  However, `kill-comment' is a valid command which you
  744. could bind directly to a key if you wanted to.
  745.  
  746. 
  747. File: emacs,  Node: Multi-Line Comments,  Next: Options for Comments,  Prev: Comment Commands,  Up: Comments
  748.  
  749. Multiple Lines of Comments
  750. --------------------------
  751.  
  752.    If you are typing a comment and wish to continue it on another line,
  753. you can use the command `M-LFD' (`indent-new-comment-line').  This
  754. terminates the comment you are typing, creates a new blank line
  755. afterward, and begins a new comment indented under the old one.  When
  756. Auto Fill mode is on, going past the fill column while typing a comment
  757. causes the comment to be continued in just this fashion.  If point is
  758. not at the end of the line when `M-LFD' is typed, the text on the rest
  759. of the line becomes part of the new comment line.
  760.  
  761.    To turn existing lines into comment lines, use the `M-x
  762. comment-region' command.  It adds comment delimiters to the lines that
  763. start in the region, thus commenting them out.  With a negative
  764. argument, it does the opposite--it deletes comment delimiters from the
  765. lines in the region.
  766.  
  767.    With a positive argument, `comment-region' duplicates the last
  768. character of the comment start sequence it adds; the argument specifies
  769. how many copies of the character to insert.  Thus, in Lisp mode, `C-u 2
  770. M-x comment-region' adds `;;' to each line.  Duplicating the comment
  771. delimiter is a way of calling attention to the comment.  It can also
  772. affect how the comment is indented.  In Lisp, for proper indentation,
  773. you should use an argument of two, if between defuns, and three, if
  774. within a defun.
  775.  
  776. 
  777. File: emacs,  Node: Options for Comments,  Prev: Multi-Line Comments,  Up: Comments
  778.  
  779. Options Controlling Comments
  780. ----------------------------
  781.  
  782.    The comment column is stored in the variable `comment-column'.  You
  783. can set it to a number explicitly.  Alternatively, the command `C-x ;'
  784. (`set-comment-column') sets the comment column to the column point is
  785. at.  `C-u C-x ;' sets the comment column to match the last comment
  786. before point in the buffer, and then does a `M-;' to align the current
  787. line's comment under the previous one.  Note that `C-u - C-x ;' runs
  788. the function `kill-comment' as described above.
  789.  
  790.    The variable `comment-column' is per-buffer: setting the variable in
  791. the normal fashion affects only the current buffer, but there is a
  792. default value which you can change with `setq-default'.  *Note
  793. Locals::.  Many major modes initialize this variable for the current
  794. buffer.
  795.  
  796.    The comment commands recognize comments based on the regular
  797. expression that is the value of the variable `comment-start-skip'.
  798. Make sure this regexp does not match the null string.  It may match more
  799. than the comment starting delimiter in the strictest sense of the word;
  800. for example, in C mode the value of the variable is `"/\\*+ *"', which
  801. matches extra stars and spaces after the `/*' itself.  (Note that `\\'
  802. is needed in Lisp syntax to include a `\' in the string, which is
  803. needed to deny the first star its special meaning in regexp syntax.
  804. *Note Regexps::.)
  805.  
  806.    When a comment command makes a new comment, it inserts the value of
  807. `comment-start' to begin it.  The value of `comment-end' is inserted
  808. after point, so that it will follow the text that you will insert into
  809. the comment.  In C mode, `comment-start' has the value `"/* "' and
  810. `comment-end' has the value `" */"'.
  811.  
  812.    The variable `comment-multi-line' controls how `M-LFD'
  813. (`indent-new-comment-line') behaves when used inside a comment.  If
  814. `comment-multi-line' is `nil', as it normally is, then the comment on
  815. the starting line is terminated and a new comment is started on the new
  816. following line.  If `comment-multi-line' is not `nil', then the new
  817. following line is set up as part of the same comment that was found on
  818. the starting line.  This is done by not inserting a terminator on the
  819. old line, and not inserting a starter on the new line.  In languages
  820. where multi-line comments work, the choice of value for this variable
  821. is a matter of taste.
  822.  
  823.    The variable `comment-indent-function' should contain a function
  824. that will be called to compute the indentation for a newly inserted
  825. comment or for aligning an existing comment.  It is set differently by
  826. various major modes.  The function is called with no arguments, but with
  827. point at the beginning of the comment, or at the end of a line if a new
  828. comment is to be inserted.  It should return the column in which the
  829. comment ought to start.  For example, in Lisp mode, the indent hook
  830. function bases its decision on how many semicolons begin an existing
  831. comment, and on the code in the preceding lines.
  832.  
  833. 
  834. File: emacs,  Node: Balanced Editing,  Next: Symbol Completion,  Prev: Comments,  Up: Programs
  835.  
  836. Editing Without Unbalanced Parentheses
  837. ======================================
  838.  
  839. `M-('
  840.      Put parentheses around next sexp(s) (`insert-parentheses').
  841.  
  842. `M-)'
  843.      Move past next close parenthesis and re-indent
  844.      (`move-over-close-and-reindent').
  845.  
  846.    The commands `M-(' (`insert-parentheses') and `M-)'
  847. (`move-over-close-and-reindent') are designed to facilitate a style of
  848. editing which keeps parentheses balanced at all times.  `M-(' inserts a
  849. pair of parentheses, either together as in `()', or, if given an
  850. argument, around the next several sexps.  It leaves point after the
  851. open parenthesis.  The command `M-)' moves past the close parenthesis,
  852. deleting any indentation preceding it (in this example there is none),
  853. and indenting with LFD after it.
  854.  
  855.    For example, instead of typing `( F O O )', you can type `M-( F O
  856. O', which has the same effect except for leaving the cursor before the
  857. close parenthesis.
  858.  
  859.    `M-(' may insert a space before the open parenthesis, depending on
  860. the syntax class of the preceding character.  Set
  861. `parens-dont-require-spaces' to a non-`nil' value if you wish to
  862. inhibit this.
  863.  
  864. 
  865. File: emacs,  Node: Symbol Completion,  Next: Documentation,  Prev: Balanced Editing,  Up: Programs
  866.  
  867. Completion for Symbol Names
  868. ===========================
  869.  
  870.    Usually completion happens in the minibuffer.  But one kind of
  871. completion is available in all buffers: completion for symbol names.
  872.  
  873.    The character `M-TAB' runs a command to complete the partial symbol
  874. before point against the set of meaningful symbol names.  Any
  875. additional characters determined by the partial name are inserted at
  876. point.
  877.  
  878.    If the partial name in the buffer has more than one possible
  879. completion and they have no additional characters in common, a list of
  880. all possible completions is displayed in another window.
  881.  
  882.    There are two ways of determining the set of legitimate symbol names
  883. to complete against.  In most major modes, this uses a tags table
  884. (*note Tags::.); the legitimate symbol names are the tag names listed in
  885. the tags table file.  The command which implements this is
  886. `complete-tag'.
  887.  
  888.    In Emacs-Lisp mode, the name space for completion normally consists
  889. of nontrivial symbols present in Emacs--those that have function
  890. definitions, values or properties.  However, if there is an
  891. open-parenthesis immediately before the beginning of the partial symbol,
  892. only symbols with function definitions are considered as completions.
  893. The command which implements this is `lisp-complete-symbol'.
  894.  
  895.    In Text mode and related modes, `M-TAB' completes words based on the
  896. spell-checker's dictionary.  *Note Spelling::.
  897.  
  898. 
  899. File: emacs,  Node: Documentation,  Next: Change Log,  Prev: Symbol Completion,  Up: Programs
  900.  
  901. Documentation Commands
  902. ======================
  903.  
  904.    As you edit Lisp code to be run in Emacs, the commands `C-h f'
  905. (`describe-function') and `C-h v' (`describe-variable') can be used to
  906. print documentation of functions and variables that you want to call.
  907. These commands use the minibuffer to read the name of a function or
  908. variable to document, and display the documentation in a window.
  909.  
  910.    For extra convenience, these commands provide default arguments
  911. based on the code in the neighborhood of point.  `C-h f' sets the
  912. default to the function called in the innermost list containing point.
  913. `C-h v' uses the symbol name around or adjacent to point as its default.
  914.  
  915.    Documentation on operating system commands, library functions and
  916. system calls can be obtained with the `M-x manual-entry' command.  This
  917. reads a topic as an argument, and displays the "man page" on that
  918. topic.  `manual-entry' starts a background process that formats the
  919. manual page, by running the `man' program.  The result goes in a buffer
  920. named `*man TOPIC*'.  These buffers use a special major mode, Man mode,
  921. that facilitates scrolling and examining other manual pages.  For
  922. details, type `C-h m' while in a man page buffer.
  923.  
  924.    For a long man page, setting the faces properly can take substantial
  925. time.  By default, Emacs uses faces in man pages if you are using X
  926. Windows.  You can turn off use of faces in man pages by setting the
  927. variable `Man-fontify-manpage-flag' to `nil'.
  928.  
  929.    If you insert the text of a man page into an Emacs buffer in some
  930. other fashion, you can use the command `M-x Man-fontify-manpage' to
  931. perform the same conversions that `M-x manual-entry' does.
  932.  
  933.    Eventually the GNU project hopes to replace most man pages with
  934. better-organized manuals that you can browse with Info.  *Note Misc
  935. Help::.  Since this process is only partially completed, it is still
  936. useful to read manual pages.
  937.  
  938. 
  939. File: emacs,  Node: Change Log,  Next: Tags,  Prev: Documentation,  Up: Programs
  940.  
  941. Change Logs
  942. ===========
  943.  
  944.    The Emacs command `C-x 4 a' adds a new entry to the change log file
  945. for the file you are editing (`add-change-log-entry-other-window').
  946.  
  947.    A change log file contains a chronological record of when and why you
  948. have changed a program, consisting of a sequence of entries describing
  949. individual changes.  Normally it is kept in a file called `ChangeLog'
  950. in the same directory as the file you are editing, or one of its parent
  951. directories.  A single `ChangeLog' file can record changes for all the
  952. files in its directory and all its subdirectories.
  953.  
  954.    A change log entry starts with a header line that contains your name,
  955. your email address (taken from the variable `user-mail-address'), and
  956. the current date and time.  Aside from these header lines, every line
  957. in the change log starts with a space or a tab.  The bulk of the entry
  958. consists of "items", each of which starts with a line starting with
  959. whitespace and a star.  Here are two entries, each with two items:
  960.  
  961.      Wed May  5 14:11:45 1993  Richard Stallman  <rms@gnu.ai.mit.edu>
  962.      
  963.              * man.el: Rename symbols `man-*' to `Man-*'.
  964.              (manual-entry): Make prompt string clearer.
  965.      
  966.              * simple.el (blink-matching-paren-distance):
  967.              Change default to 12,000.
  968.      
  969.      Tue May  4 12:42:19 1993  Richard Stallman  <rms@gnu.ai.mit.edu>
  970.      
  971.              * vc.el (minor-mode-map-alist): Don't use it if it's void.
  972.              (vc-cancel-version): Doc fix.
  973.  
  974.    One entry can describe several changes; each change should have its
  975. own item.  Normally there should be a blank line between items.  When
  976. items are related (parts of the same change, in different places), group
  977. them by leaving no blank line between them.  The second entry above
  978. contains two items grouped in this way.
  979.  
  980.    `C-x 4 a' visits the change log file and creates a new entry unless
  981. the most recent entry is for today's date and your name.  It also
  982. creates a new item for the current file.  For many languages, it can
  983. even guess the name of the function or other object that was changed.
  984.  
  985.    The change log file is visited in Change Log mode.  In this major
  986. mode, each bunch of grouped items counts as one paragraph, and each
  987. entry is considered a page.  This facilitates editing the entries.  LFD
  988. and auto-fill indent each new line like the previous line; this is
  989. convenient for entering the contents of an entry.
  990.  
  991.    Version control systems are another way to keep track of changes in
  992. your program and keep a change log.  *Note Log Entries::.
  993.  
  994. 
  995. File: emacs,  Node: Tags,  Next: Emerge,  Prev: Change Log,  Up: Programs
  996.  
  997. Tags Tables
  998. ===========
  999.  
  1000.    A "tags table" is a description of how a multi-file program is
  1001. broken up into files.  It lists the names of the component files and the
  1002. names and positions of the functions (or other named subunits) in each
  1003. file.  Grouping the related files makes it possible to search or replace
  1004. through all the files with one command.  Recording the function names
  1005. and positions makes possible the `M-.'  command which finds the
  1006. definition of a function by looking up which of the files it is in.
  1007.  
  1008.    Tags tables are stored in files called "tags table files".  The
  1009. conventional name for a tags table file is `TAGS'.
  1010.  
  1011.    Each entry in the tags table records the name of one tag, the name
  1012. of the file that the tag is defined in (implicitly), and the position
  1013. in that file of the tag's definition.
  1014.  
  1015.    Just what names from the described files are recorded in the tags
  1016. table depends on the programming language of the described file.  They
  1017. normally include all functions and subroutines, and may also include
  1018. global variables, data types, and anything else convenient.  Each name
  1019. recorded is called a "tag".
  1020.  
  1021. * Menu:
  1022.  
  1023. * Tag Syntax::        Tag syntax for various types of code and text files.
  1024. * Create Tags Table::    Creating a tags table with `etags'.
  1025. * Select Tags Table::    How to visit a tags table.
  1026. * Find Tag::        Commands to find the definition of a specific tag.
  1027. * Tags Search::        Using a tags table for searching and replacing.
  1028. * List Tags::        Listing and finding tags defined in a file.
  1029.  
  1030. 
  1031. File: emacs,  Node: Tag Syntax,  Next: Create Tags Table,  Up: Tags
  1032.  
  1033. Source File Tag Syntax
  1034. ----------------------
  1035.  
  1036.    * In Lisp code, any function defined with `defun', any variable
  1037.      defined with `defvar' or `defconst', and in general the first
  1038.      argument of any expression that starts with `(def' in column zero,
  1039.      is a tag.
  1040.  
  1041.    * In Scheme code, tags include anything defined with `def' or with a
  1042.      construct whose name starts with `def'.  They also include
  1043.      variables set with `set!' at top level in the file.
  1044.  
  1045.    * In C code, any C function or typedef is a tag, and so are
  1046.      definitions of struct, union and enum.  Any `#define' is also a
  1047.      tag, unless `--no-defines' is specified when the tags table is
  1048.      constructed, which sometimes makes the tags file much smaller.  In
  1049.      C++ code, member functions are also recognized.
  1050.  
  1051.    * In Yacc or Bison input files, each rule defines as a tag the
  1052.      nonterminal it constructs.  The portions of the file that contain
  1053.      C code are parsed as C code.
  1054.  
  1055.    * In Fortran code, functions and subroutines are tags.
  1056.  
  1057.    * In Pascal code, the tags are the functions and procedures defined
  1058.      in the file.
  1059.  
  1060.    * In Perl code, the tags are the procedures defined by the `sub'
  1061.      keyword.
  1062.  
  1063.    * In Prolog code, a tag name appears at the left margin.
  1064.  
  1065.    * In Erlang code, the tags are the functions, records, and macros
  1066.      defined in the file.
  1067.  
  1068.    * In assembler code, labels appearing at the beginning of a line,
  1069.      followed by a colon, are tags.
  1070.  
  1071.    * In LaTeX text, the argument of any of the commands `\chapter',
  1072.      `\section', `\subsection', `\subsubsection', `\eqno', `\label',
  1073.      `\ref', `\cite', `\bibitem', `\part', `\appendix', `\entry', or
  1074.      `\index', is a tag.
  1075.  
  1076.      Other commands can make tags as well, if you specify them in the
  1077.      environment variable `TEXTAGS' before invoking `etags'.  The value
  1078.      of this environment variable should be a colon-separated list of
  1079.      commands names.  For example,
  1080.  
  1081.           TEXTAGS="def:newcommand:newenvironment"
  1082.           export TEXTAGS
  1083.  
  1084.      specifies (using Bourne shell syntax) that the commands `\def',
  1085.      `\newcommand' and `\newenvironment' also define tags.
  1086.  
  1087.    * You can also generate tags based on regexp matching (*note Create
  1088.      Tags Table::.) for any text file.
  1089.  
  1090. 
  1091. File: emacs,  Node: Create Tags Table,  Next: Select Tags Table,  Prev: Tag Syntax,  Up: Tags
  1092.  
  1093. Creating Tags Tables
  1094. --------------------
  1095.  
  1096.    The `etags' program is used to create a tags table file.  It knows
  1097. the syntax of several languages, as described in *Note Tag Syntax::.
  1098. Here is how to run `etags':
  1099.  
  1100.      etags INPUTFILES...
  1101.  
  1102. The `etags' program reads the specified files, and writes a tags table
  1103. named `TAGS' in the current working directory.  `etags' recognizes the
  1104. language used in an input file based on its file name and contents.
  1105. You can specify the language with the `--language=NAME' option,
  1106. described below.
  1107.  
  1108.    If the tags table data become outdated due to changes in the files
  1109. described in the table, the way to update the tags table is the same
  1110. way it was made in the first place.  It is not necessary to do this
  1111. often.
  1112.  
  1113.    If the tags table fails to record a tag, or records it for the wrong
  1114. file, then Emacs cannot possibly find its definition.  However, if the
  1115. position recorded in the tags table becomes a little bit wrong (due to
  1116. some editing in the file that the tag definition is in), the only
  1117. consequence is a slight delay in finding the tag.  Even if the stored
  1118. position is very wrong, Emacs will still find the tag, but it must
  1119. search the entire file for it.
  1120.  
  1121.    So you should update a tags table when you define new tags that you
  1122. want to have listed, or when you move tag definitions from one file to
  1123. another, or when changes become substantial.  Normally there is no need
  1124. to update the tags table after each edit, or even every day.
  1125.  
  1126.    One tags table can effectively include another.  Specify the included
  1127. tags file name with the `--include=FILE' option when creating the file
  1128. that is to include it.  The latter file then acts as if it contained
  1129. all the files specified in the included file, as well as the files it
  1130. directly contains.
  1131.  
  1132.    If you specify the source files with relative file names when you run
  1133. `etags', the tags file will contain file names relative to the
  1134. directory where the tags file was initially written.  This way, you can
  1135. move an entire directory tree containing both the tags file and the
  1136. source files, and the tags file will still refer correctly to the source
  1137. files.
  1138.  
  1139.    If you specify absolute file names as arguments to `etags', then the
  1140. tags file will contain absolute file names.  This way, the tags file
  1141. will still refer to the same files even if you move it, as long as the
  1142. source files remain in the same place.  Absolute file names start with
  1143. `/', or with `DEVICE:/' on MS-DOS and Windows.
  1144.  
  1145.    When you want to make a tags table from a great number of files, you
  1146. may have problems listing them on the command line, because some systems
  1147. have a limit on its length.  The simplest way to circumvent this limit
  1148. is to tell `etags' to read the file names from its standard input, by
  1149. typing a dash in place of the file names, like this:
  1150.  
  1151.      find . -name "*.[chCH]" -print | etags -
  1152.  
  1153.    Use the option `--language=NAME' to specify the language explicitly.
  1154. You can intermix these options with file names; each one applies to
  1155. the file names that follow it.  Specify `--language=auto' to tell
  1156. `etags' to resume guessing the language from the file names and file
  1157. contents.  Specify `--language=none' to turn off language-specific
  1158. processing entirely; then `etags' recognizes tags by regexp matching
  1159. alone.  `etags --help' prints the list of the languages `etags' knows,
  1160. and the file name rules for guessing the language.
  1161.  
  1162.    The `--regex' option provides a general way of recognizing tags
  1163. based on regexp matching.  You can freely intermix it with file names.
  1164. Each `--regex' option adds to the preceding ones, and applies only to
  1165. the following files.  The syntax is:
  1166.  
  1167.      --regex=/TAGREGEXP[/NAMEREGEXP]/
  1168.  
  1169. where TAGREGEXP is used to match the lines to tag.  It is always
  1170. anchored, that is, it behaves as if preceded by `^'.  If you want to
  1171. account for indentation, just match any initial number of blanks by
  1172. beginning your regular expression with `[ \t]*'.  In the regular
  1173. expressions, `\' quotes the next character, and `\t' stands for the tab
  1174. character.  Note that `etags' does not handle the other C escape
  1175. sequences for special characters.
  1176.  
  1177.    You should not match more characters with TAGREGEXP than that needed
  1178. to recognize what you want to tag.  If the match is such that more
  1179. characters than needed are unavoidably matched by TAGREGEXP, you may
  1180. find useful to add a NAMEREGEXP, in order to narrow the tag scope.  You
  1181. can find some examples below.
  1182.  
  1183.    The `-R' option deletes all the regexps defined with `--regex'
  1184. options.  It applies to the file names following it, as you can see
  1185. from the following example:
  1186.  
  1187.      etags --regex=/REG1/ voo.doo --regex=/REG2/ \
  1188.          bar.ber -R --lang=lisp los.er
  1189.  
  1190. Here `etags' chooses the parsing language for `voo.doo' and `bar.ber'
  1191. according to their contents.  `etags' also uses REG1 to recognize
  1192. additional tags in `voo.doo', and both REG1 and REG2 to recognize
  1193. additional tags in `bar.ber'.  `etags' uses the Lisp tags rules, and no
  1194. regexp matching, to recognize tags in `los.er'.
  1195.  
  1196.    Here are some more examples.  The regexps are quoted to protect them
  1197. from shell interpretation.
  1198.  
  1199. Tag the `DEFVAR' macros in the emacs source files:
  1200.  
  1201.      --regex='/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'
  1202.  
  1203. Tag VHDL files (this example is a single long line, broken here for
  1204. formatting reasons):
  1205.  
  1206.      --language=none
  1207.      --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/'
  1208.      --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\
  1209.      \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'
  1210.  
  1211. Tag Cobol files (every label starting in column seven):
  1212.  
  1213.      --language=none --regex='/.......[a-zA-Z0-9-]+\./'
  1214.  
  1215. Tag Postscript files (every label starting in column one):
  1216.  
  1217.      --language=none --regex='#/[^ \t{]+#/'
  1218.  
  1219. Tag TCL files (this last example shows the usage of a NAMEREGEXP):
  1220.  
  1221.      --lang=none --regex='/proc[ \t]+\([^ \t]+\)/\1/'
  1222.  
  1223.    For a list of the other available `etags' options, execute `etags
  1224. --help'.
  1225.  
  1226.